/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * MenuAgenda.java
 *
 * Created on 5/Dez/2011, 13:59:56
 */
package desint;

import java.awt.CardLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.JOptionPane;
import javax.swing.JTable;
import javax.swing.table.TableCellEditor;
import popup.AgendaAddAtiv;
import popup.AgendaUtil;

/**
 *
 * @author lenny
 */
public class MenuAgendaSocio extends javax.swing.JPanel {
    
    private JanelaPrincipal jp;
    private String salaSel;
    private String horaSel;

    /** Creates new form MenuAgenda */
    public MenuAgendaSocio() {
        initComponents();
        inscrever.setEnabled(false);
        salaSel="Yoga";
        horaSel="9:00";
    }
    
    public void setJanelaPrincipal(JanelaPrincipal jp){
        this.jp = jp;
        checkCell();
    }
    
    
    private void changeSala(String s){
        salaSel=s;
         //System.out.println(s);
        CardLayout card = (CardLayout)(cardHolder.getLayout());
        if(s.equals("Yoga") || s.equals("Pilates")){
           
            card.show(cardHolder, "card1");
        } else if(s.equals("Defesa Pessoal")){
            card.show(cardHolder, "card2");
       } else if(s.equals("Kickboxing")){
            card.show(cardHolder, "card3");
        }
    }
    
    public void checkCell(){
        sala.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
               //System.out.println(sala.getSelectedItem());
                changeSala(sala.getSelectedItem().toString());
            }
        });

        agenda.addMouseListener(new MouseAdapter() {

            public void mousePressed(MouseEvent me) {
                //System.out.println(me); 
                selectedCell(agenda);
            }
        });
        
        agenda1.addMouseListener(new MouseAdapter() { 
          public void mousePressed(MouseEvent me) { 
            //System.out.println(me); 
            selectedCell(agenda1);
          } 
        }); 
        
        agenda2.addMouseListener(new MouseAdapter() { 
          public void mousePressed(MouseEvent me) { 
            //System.out.println(me); 
            selectedCell(agenda2);
          } 
        }); 
    }
    
    private void selectedCell(JTable curr) {
        int row = curr.getSelectedRow();
        int col = curr.getSelectedColumn();
        String v;
        
        horaSel = curr.getValueAt(row, 0).toString();
        //System.out.println(curr.getValueAt(row, 0));
        
        Object val = curr.getValueAt(row, col);
        if (val !=null){
            v = val.toString();
        } else {
            v = "";
        }
        
        //System.out.println("Cell value: " + val);
        if (!v.isEmpty()) {
            inscrever.setEnabled(true);
        } else {
            inscrever.setEnabled(false);
        }

    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jButton1 = new javax.swing.JButton();
        inscrever = new javax.swing.JButton();
        cardHolder = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        agenda = new javax.swing.JTable();
        jScrollPane2 = new javax.swing.JScrollPane();
        agenda1 = new javax.swing.JTable();
        jScrollPane3 = new javax.swing.JScrollPane();
        agenda2 = new javax.swing.JTable();
        jLabel1 = new javax.swing.JLabel();
        sala = new javax.swing.JComboBox();
        jLabel2 = new javax.swing.JLabel();
        jButton4 = new javax.swing.JButton();
        jButton5 = new javax.swing.JButton();
        jLabel3 = new javax.swing.JLabel();
        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();

        setBackground(new java.awt.Color(255, 255, 255));

        jButton1.setText("jButton1");

        inscrever.setText("Inscrever");
        inscrever.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                inscreverMouseClicked(evt);
            }
        });

        cardHolder.setLayout(new java.awt.CardLayout());

        agenda.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {"8:00", null, null, null, null, null, null, null},
                {"8:30", null, "", null, null, null, null, null},
                {"9:00", null, "Pilates", null, null, null, null, null},
                {"9:30", "Yoga", "Pilates", "", "Yoga", null, null, null},
                {"10:00", "Yoga", null, null, "Yoga", null, "", null},
                {"10:30", "Yoga", null, null, "Yoga", null, "", null},
                {"11:00", null, null, null, null, null, null, null},
                {"11:30", null, null, "Pilates", null, null, null, null},
                {"12:00", null, null, "Pilates", null, null, null, null},
                {"12:30", null, null, null, null, null, null, null},
                {"13:00", null, null, null, null, null, null, null},
                {"13:30", null, null, null, null, null, null, null},
                {"14:00", null, null, null, null, null, null, null},
                {"14:30", null, null, null, null, null, null, null},
                {"15:00", null, null, null, null, null, null, null},
                {"15:30", null, null, null, null, null, null, null},
                {"16:00", null, null, null, null, null, null, null},
                {"16:30", null, null, null, null, null, null, null},
                {"17:00", "Yoga", null, null, "Yoga", null, null, null},
                {"17:30", "Yoga", null, null, "Yoga", null, null, null},
                {"18:00", "Yoga", null, null, "Yoga", null, null, null},
                {"18:30", null, null, null, null, null, null, null},
                {"19:00", null, null, null, null, null, null, null}
            },
            new String [] {
                "Hora", "Segunda", "Terça", "Quarta", "Quinta", "Sexta", "Sabado", "Domingo"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false, false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        agenda.setRowSelectionAllowed(false);
        jScrollPane1.setViewportView(agenda);
        agenda.getColumnModel().getSelectionModel().setSelectionMode(javax.swing.ListSelectionModel.SINGLE_INTERVAL_SELECTION);

        cardHolder.add(jScrollPane1, "card1");

        agenda1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {"8:00", null, null, null, null, null, null, null},
                {"8:30", null, "", null, null, null, null, null},
                {"9:00", null, "", null, null, null, null, null},
                {"9:30", "Defesa Pessoal", "", "", "", null, null, null},
                {"10:00", "Defesa Pessoal", null, null, "", null, "", null},
                {"10:30", "", null, null, "", null, "", null},
                {"11:00", null, null, null, null, null, null, null},
                {"11:30", null, null, "", null, null, null, null},
                {"12:00", null, null, "", null, null, null, null},
                {"12:30", null, null, null, null, null, null, null},
                {"13:00", null, null, null, null, null, null, null},
                {"13:30", null, null, null, null, null, null, null},
                {"14:00", null, null, null, null, null, null, null},
                {"14:30", null, null, null, null, null, null, null},
                {"15:00", null, null, null, null, null, null, null},
                {"15:30", null, null, null, null, null, null, null},
                {"16:00", null, null, null, null, null, null, null},
                {"16:30", null, null, null, null, null, null, null},
                {"17:00", "", null, null, "", null, null, null},
                {"17:30", "", null, null, "", null, null, null},
                {"18:00", "Defesa Pessoal", null, null, "", null, null, null},
                {"18:30", "Defesa Pessoal", null, null, null, null, null, null},
                {"19:00", null, null, null, null, null, null, null}
            },
            new String [] {
                "Hora", "Segunda", "Terça", "Quarta", "Quinta", "Sexta", "Sabado", "Domingo"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false, false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        agenda1.setRowSelectionAllowed(false);
        jScrollPane2.setViewportView(agenda1);
        agenda1.getColumnModel().getSelectionModel().setSelectionMode(javax.swing.ListSelectionModel.SINGLE_INTERVAL_SELECTION);

        cardHolder.add(jScrollPane2, "card2");

        agenda2.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {"8:00", null, null, null, null, null, null, null},
                {"8:30", null, "", null, null, null, null, null},
                {"9:00", null, "Kickboxing", null, "Kickboxing", null, null, null},
                {"9:30", "", "Kickboxing", "", "Kickboxing", null, null, null},
                {"10:00", "", null, null, "", null, "Kickboxing", null},
                {"10:30", "", null, null, "", null, "Kickboxing", null},
                {"11:00", null, null, null, null, null, null, null},
                {"11:30", null, null, "", null, null, null, null},
                {"12:00", "Kickboxing", null, "", null, "Kickboxing", null, null},
                {"12:30", "Kickboxing", null, null, null, "Kickboxing", null, null},
                {"13:00", null, null, null, null, null, null, null},
                {"13:30", null, null, null, null, null, null, null},
                {"14:00", null, null, null, null, null, null, null},
                {"14:30", null, null, null, null, null, "Defesa Pessoal", null},
                {"15:00", null, null, null, null, null, "Defesa Pessoal", null},
                {"15:30", null, null, null, null, null, null, null},
                {"16:00", null, null, null, null, null, null, null},
                {"16:30", null, null, null, null, null, null, null},
                {"17:00", "", "Kickboxing", null, "Kickboxing", null, null, null},
                {"17:30", "", "Kickboxing", null, "Kickboxing", null, null, null},
                {"18:00", "", null, null, "", null, null, null},
                {"18:30", null, null, null, null, null, null, null},
                {"19:00", null, null, null, null, null, null, null}
            },
            new String [] {
                "Hora", "Segunda", "Terça", "Quarta", "Quinta", "Sexta", "Sabado", "Domingo"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false, false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        agenda2.setRowSelectionAllowed(false);
        jScrollPane3.setViewportView(agenda2);
        agenda2.getColumnModel().getSelectionModel().setSelectionMode(javax.swing.ListSelectionModel.SINGLE_INTERVAL_SELECTION);

        cardHolder.add(jScrollPane3, "card3");

        jLabel1.setFont(new java.awt.Font("Tahoma", 0, 18));
        jLabel1.setText("Atividade");

        sala.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Yoga", "Pilates", "Defesa Pessoal", "Kickboxing" }));

        jLabel2.setText("Semana de 16 Janeiro a  22 Janeiro");
        jLabel2.setToolTipText("");

        jButton4.setText("Proximo");

        jButton5.setText("Anterior");

        jLabel3.setFont(new java.awt.Font("Tahoma", 1, 13)); // NOI18N
        jLabel3.setText("Janeiro 2012");

        jButton2.setText("Proximo");

        jButton3.setText("Anterior");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(inscrever))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addGap(53, 53, 53)
                        .addComponent(jLabel1)
                        .addGap(35, 35, 35)
                        .addComponent(sala, javax.swing.GroupLayout.PREFERRED_SIZE, 96, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 120, Short.MAX_VALUE)
                        .addComponent(jButton3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jButton2)))
                .addContainerGap(90, Short.MAX_VALUE))
            .addGroup(layout.createSequentialGroup()
                .addGap(41, 41, 41)
                .addComponent(cardHolder, javax.swing.GroupLayout.PREFERRED_SIZE, 723, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(90, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(440, Short.MAX_VALUE)
                .addComponent(jButton5)
                .addGap(18, 18, 18)
                .addComponent(jLabel3)
                .addGap(18, 18, 18)
                .addComponent(jButton4)
                .addGap(137, 137, 137))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel1)
                        .addComponent(sala, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel2)
                        .addComponent(jButton2)
                        .addComponent(jButton3)))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton4)
                    .addComponent(jLabel3)
                    .addComponent(jButton5))
                .addGap(37, 37, 37)
                .addComponent(cardHolder, javax.swing.GroupLayout.PREFERRED_SIZE, 248, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(inscrever, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

    private void inscreverMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_inscreverMouseClicked
        if (inscrever.isEnabled()){
        JOptionPane.showMessageDialog(null, "Foi inscrito com sucesso nesta Atvidade", "Inscrever Atividade", JOptionPane.INFORMATION_MESSAGE);
        }
        
    }//GEN-LAST:event_inscreverMouseClicked

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTable agenda;
    private javax.swing.JTable agenda1;
    private javax.swing.JTable agenda2;
    private javax.swing.JPanel cardHolder;
    private javax.swing.JButton inscrever;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JComboBox sala;
    // End of variables declaration//GEN-END:variables

    
}
